//
//  CLUserInfo.m
//  Charles
//
//  Created by Charles on 2017/6/20.
//  Copyright © 2017年 charles. All rights reserved.
//

#import "CLUserInfo.h"


static CLUserInfo *userInfo = nil;

@implementation CLUserInfo
@synthesize myAge = _myAge;
@dynamic age;

/*
 atomic 属性效果如下代码
 */

- (void)setAge:(NSInteger)age {
    @synchronized (self) {
        _age = age;
        _myAge = _age;
    }
}

- (NSInteger)age {
    return _age;
}

- (NSInteger)myAge {
    return _myAge;
}

+ (instancetype)sharedInstance {
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        userInfo = [[CLUserInfo alloc]init];
    });
    return userInfo;
}

+ (instancetype)allocWithZone:(struct _NSZone *)zone {
    if (userInfo == nil) {
        static dispatch_once_t onceToken;
        dispatch_once(&onceToken, ^{
            userInfo = [super allocWithZone:zone];
        });
    }
    return userInfo;
}

+ (id)copyWithZone:(struct _NSZone *)zone {
    return userInfo;
}

+ (id)mutableCopyWithZone:(struct _NSZone *)zone {
    return userInfo;
}

@end
